﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext.Web;
public partial class Search_Company_View : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["id"] != null)
        {
            string id = Request["id"];
            Query q = new Query(CxApply.Schema);
            q.AddWhere("id", id);
            q.AddWhere("uid", Cookies.getCookies("cuid"));
            q.SetSelectList("bossnod,counttimes,guid");
            if (q.GetRecordCount() > 0)
            {
                IDataReader dr = q.ExecuteReader();
                if (dr.Read())
                {
                    if (dr["bossnod"].ToString() == "0")
                    {
                        Ext.MessageBox.Show(new MessageBox.Config
                        {
                            Buttons = MessageBox.Button.OK,
                            Icon = MessageBox.Icon.ERROR,
                            Title = "错误！",
                            Message = "请等待审核！"
                        });
                    }
                    if (dr["bossnod"].ToString() == "1")
                    {
                        if (dr["counttimes"].ToString() == "0")
                        {
                            Ext.MessageBox.Show(new MessageBox.Config
                            {
                                Buttons = MessageBox.Button.OK,
                                Icon = MessageBox.Icon.ERROR,
                                Title = "错误！",
                                Message = "查询次数已用完！"
                            });
                        }
                        else
                        {
                            //开始输出数据
                            Query query = new Query(VwCompanyPingjium.Schema);
                            query.AddWhere("guid", dr["guid"].ToString());
                            IDataReader r = query.ExecuteReader();
                            if (r.Read())
                            {
                                tfcompanyid.Text = r["companyid"].ToString();
                                tfcompanyname.Text = r["companyname"].ToString();
                                tfunfee_time.Text = r["unfee_time"].ToString();
                                tfunfee_cash.Text = r["unfee_cash"].ToString();
                                tfunfee_detail.Text = r["unfee_detail"].ToString();
                                tfthief_time1_time2.Text = r["thief_time1"].ToString() + "至" +
                                                           r["thief_time2"].ToString();
                                tfthief_cash.Text = r["thief_cash"].ToString();
                                tfthief_detail.Text = r["thief_detail"].ToString();
                                tfuncoop_peak_time.Text = r["uncoop_peak_time"].ToString();
                                tfuncoop_peak_detail.Text = r["uncoop_peak_detail"].ToString();
                                tfuncoop_limit_time.Text = r["uncoop_limit_time"].ToString();
                                tfuncoop_limit_detail.Text = r["uncoop_limit_detail"].ToString();
                                tfuncoop_others.Text = r["uncoop_others"].ToString();
                                tfenter_username.Text = r["enter_username"].ToString();
                                tfenter_deptname.Text = r["enter_deptname"].ToString();
                                tfdept_master_id.Text = Username(r["dept_master_id"].ToString());
                                tfdept_master_status.Text = Status(r["dept_master_status"].ToString());
                                tfdept_master_entering_time.Text = r["dept_master_entering_time"].ToString();
                                tfdept_master_remark.Text = r["dept_master_remark"].ToString();
                                tfmanager_id.Text = Username(r["manager_id"].ToString());
                                tfmanager_remark_time.Text = r["manager_remark_time"].ToString();
                                tfmanager_status.Text = Status(r["manager_status"].ToString());
                                tfmanagerremark.Text = r["manager_remark"].ToString();
                                tfintime.Text = r["intime"].ToString();
                                string[] str = CXFileUpload.show(new Guid(dr["guid"].ToString())).Split('$');
                                tfzip.Text = str[1];
                                tfzip.NavigateUrl = str[0];
                            }
                        }
                    }
                    if (dr["bossnod"].ToString() == "2")
                    {
                        Ext.MessageBox.Show(new MessageBox.Config
                        {
                            Buttons = MessageBox.Button.OK,
                            Icon = MessageBox.Icon.ERROR,
                            Title = "错误！",
                            Message = "您的申请已被管理员拒绝，请重新申请！"
                        });
                    }
                }
            }
            else
            {
                Ext.MessageBox.Show(new MessageBox.Config
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.ERROR,
                    Title = "错误！",
                    Message = "数据库中没有记录！"
                });
            }
        }
    }
    protected string Username(string uid)
    {
        if (uid == "")
        {
            return "未指定";
        }
        Query q = new Query(CxUserBase.Schema);
        q.AddWhere("uid", uid);
        q.SetSelectList("username");
        return q.ExecuteScalar().ToString();
    }
    protected string Status(string s)
    {
        switch (s)
        {
            case "0":
                return "未审核";
                break;
            case "1":
                return "同意";
                break;
            case "2":
                return "退回";
                break;
            default:
                break;
        }
        return "未知";
    }
}
